<template>
  <div class="phone">
    <van-tabs v-model="active">
      <van-tab v-for="item in phoneList" :key="item.id">
        <template #title>
          <div @click="getCategory(item.id)">
            {{ item.name }}
          </div>
        </template>
        <div class="phone-list">
          <div class="phone-item" v-for="item in list" :key="item.id">
            <div class="img">
              <img :src="item.img_url" alt="" />
            </div>
            <div class="p-name">{{ item.name }}</div>
            <div class="p-con">{{ item.content }}</div>
            <div class="p-price">￥{{ item.price }}</div>
          </div>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>
<script>
import { getPhone } from '../../../api'
export default {
  data() {
    return {
      active: 0,
      phoneList: [],
      list: []
    }
  },
  methods: {
    async getPhoneList() {
      const res = await getPhone()
      this.phoneList = res.data
    },
    async getCategory(id) {
      const res = await getPhone()
      res.data.forEach(item => {
        if (id === item.id) {
          this.list = item.data
        }
      })
      // console.log(this.list)
    }
  },
  created() {
    this.getPhoneList()
    this.getCategory(1)
  }
}
</script>
<style lang="scss" scoped>
.phone-list {
  display: flex;
  flex-wrap: wrap;

  text-align: center;
  .phone-item {
    border: 1px solid #f7f7f7;
    flex: 0.5;
    width: 48%;
    padding: 10px;
    box-sizing: border-box;
    .img {
      width: 185px;
      height: 185px;
      img {
        width: 180px;
        height: 180px;
        margin-left: 5px;
      }
    }
    .p-name {
      width: 80%;
      font-size: 16px;
      font-weight: 500;
      margin: 3px auto;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .p-con {
      width: 80%;
      font-size: 14px;
      margin: 3px auto;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .p-price {
      width: 80%;
      font-size: 14px;
      margin: 3px auto;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
      color: red;
    }
  }
}
</style>